Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

363
Visualizações
Flutter | FireStore Error: RangeError (index): Index out of range: index should be less than 1: 1

I am trying to get the list of documents from a collection but having the out-of-range error. You can see the function that returns the list and the output afterward.

Future<List> getPreAppliedUserList() async {
    try {
      List? userList = [""];
      QuerySnapshot querySnapshot =
          await _db!.collection(_preAppliedUserCollection).get();
      List allData = querySnapshot.docs.map((doc) => doc.data()).toList();
      print(allData.length); /// 2
      for (int i = 0; i <= allData.length; i++) {
        userList[i] = await allData[i]['customerNumber'];
      }
      return userList;
    } on FirebaseException {
      print("getPreAppliedUserList error");
      var x; ///todo
      return x;
    }
  }

Error:

Error: RangeError (index): Index out of range: index should be less than 1: 1
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Arrays are 0-indexed, and the allData.length is of length 2. Therefore you should use:

for (int i = 0; i < allData.length; i++) {
    userList[i] = await allData[i]['customerNumber'];
}

which means remove the <= and replace it with < since you don't have an item with index 2

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda